home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / ip.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  7.9 KB  |  240 lines

  1. #ifndef    _IP_H
  2. #define    _IP_H
  3.  
  4. #ifndef    _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.  
  8. #ifndef    _MBUF_H
  9. #include "mbuf.h"
  10. #endif
  11.  
  12. #ifndef    _IFACE_H
  13. #include "iface.h"
  14. #endif
  15.  
  16. #ifndef    _INTERNET_H
  17. #include "internet.h"
  18. #endif
  19.  
  20. #ifndef    _TIMER_H
  21. #include "timer.h"
  22. #endif
  23.  
  24. #define    TLB    30    /* Default reassembly timeout, sec */
  25. #define    IPVERSION    4
  26. #define    IP_MAXOPT    40    /* Largest option field, bytes */
  27.  
  28. extern int32 Ip_addr;    /* Our IP address for ICMP and source routing */
  29. extern char Hashtab[];    /* Modulus lookup table */
  30.  
  31. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  32. extern struct mib_entry Ip_mib[];
  33. #define    ipForwarding        Ip_mib[1].value.integer
  34. #define    ipDefaultTTL        Ip_mib[2].value.integer
  35. #define    ipInReceives        Ip_mib[3].value.integer
  36. #define    ipInHdrErrors        Ip_mib[4].value.integer
  37. #define    ipInAddrErrors        Ip_mib[5].value.integer
  38. #define    ipForwDatagrams        Ip_mib[6].value.integer
  39. #define    ipInUnknownProtos    Ip_mib[7].value.integer
  40. #define    ipInDiscards        Ip_mib[8].value.integer
  41. #define    ipInDelivers        Ip_mib[9].value.integer
  42. #define    ipOutRequests        Ip_mib[10].value.integer
  43. #define    ipOutDiscards        Ip_mib[11].value.integer
  44. #define    ipOutNoRoutes        Ip_mib[12].value.integer
  45. #define    ipReasmTimeout        Ip_mib[13].value.integer
  46. #define    ipReasmReqds        Ip_mib[14].value.integer
  47. #define    ipReasmOKs        Ip_mib[15].value.integer
  48. #define    ipReasmFails        Ip_mib[16].value.integer
  49. #define    ipFragOKs        Ip_mib[17].value.integer
  50. #define    ipFragFails        Ip_mib[18].value.integer
  51. #define    ipFragCreates        Ip_mib[19].value.integer
  52.  
  53. #define    NUMIPMIB    19
  54.  
  55. /* IP header, INTERNAL representation */
  56. struct ip {
  57.     char version;        /* IP version number */
  58.     char tos;        /* Type of service */
  59.     int16 length;        /* Total length */
  60.     int16 id;        /* Identification */
  61.     int16 offset;        /* Fragment offset in bytes */
  62.     struct {
  63.         char congest;    /* Congestion experienced bit (exp) */
  64.         char df;    /* Don't fragment flag */
  65.         char mf;    /* More Fragments flag */
  66.     } flags;
  67.  
  68.     char ttl;        /* Time to live */
  69.     char protocol;        /* Protocol */
  70.     int16 checksum;        /* Header checksum */
  71.     int32 source;        /* Source address */
  72.     int32 dest;        /* Destination address */
  73.     char options[IP_MAXOPT];/* Options field */
  74.     int optlen;        /* Length of options field, bytes */
  75. };
  76. #define    NULLIP    (struct ip *)0
  77. #define    IPLEN    20    /* Length of standard IP header */
  78.  
  79. /* Fields in option type byte */
  80. #define    OPT_COPIED    0x80    /* Copied-on-fragmentation flag */
  81. #define    OPT_CLASS    0x60    /* Option class */
  82. #define    OPT_NUMBER    0x1f    /* Option number */
  83.  
  84. /* IP option numbers */
  85. #define    IP_EOL        0    /* End of options list */
  86. #define    IP_NOOP        1    /* No Operation */
  87. #define    IP_SECURITY    2    /* Security parameters */
  88. #define    IP_LSROUTE    3    /* Loose Source Routing */
  89. #define    IP_TIMESTAMP    4    /* Internet Timestamp */
  90. #define    IP_RROUTE    7    /* Record Route */
  91. #define    IP_STREAMID    8    /* Stream ID */
  92. #define    IP_SSROUTE    9    /* Strict Source Routing */
  93.  
  94. /* Timestamp option flags */
  95. #define    TS_ONLY        0    /* Time stamps only */
  96. #define    TS_ADDRESS    1    /* Addresses + Time stamps */
  97. #define    TS_PRESPEC    3    /* Prespecified addresses only */
  98.  
  99. /* IP routing table entry */
  100. struct route {
  101.     struct route *prev;    /* Linked list pointers */
  102.     struct route *next;
  103.     int32 target;        /* Target IP address */
  104.     unsigned int bits;    /* Number of significant bits in target */
  105.     int32 gateway;        /* IP address of local gateway for this target */
  106.     int32 metric;        /* Hop count or whatever */
  107.     struct iface *iface;    /* Device interface structure */
  108.     int flags;
  109. #define    RTPRIVATE    0x1    /* Should the world be told of this route ? */
  110. #define    RTTRIG    0x2        /* Trigger is pending for this route */
  111.     struct timer timer;    /* Time until aging of this entry */
  112.     int32 uses;        /* Usage count */
  113. };
  114.  
  115. /* IP access header entry  (WFM) */
  116. void addaccess __ARGS((int16 protocol,int32 source,unsigned int sbits,
  117. int32 target,unsigned int tbits,struct iface *ifp,
  118. int16 low,int16 high,int16 permit));
  119.  
  120. struct rtaccess{
  121.     struct rtaccess *nxtiface;  /* Linked list pointer */
  122.     struct rtaccess *nxtbits;
  123.     int16 status;       /* 0=permit, 1=deny */
  124.     int16 protocol;     /* 0=any, otherwise IP protocol # */
  125.     int32 source;       /* Source IP address */
  126.     unsigned int sbits; /* Number of significant bits in source */
  127.     int32 target;       /* Target IP address */
  128.     unsigned int bits;  /* Number of significant bits in target */
  129.     struct iface *iface;    /* Device interface structure */
  130.     int16 lowport;      /* tcp & udp port range. low=0 implies all */
  131.     int16 highport;
  132. };
  133. #define NULLACCESS  (struct rtaccess *)0
  134. extern struct rtaccess *IPaccess;
  135. /* end WFM access control */
  136.  
  137.  
  138. #define    NULLROUTE    (struct route *)0
  139. extern struct route *Routes[32][HASHMOD];    /* Routing table */
  140. extern struct route R_default;            /* Default route entry */
  141.  
  142. /* IP routing save table entry - DB3FL */
  143. struct ip_saverecord {
  144.     int32 target;
  145.     int bits;
  146.     int32 gateway;
  147.     int niface;
  148.     int32 metric;
  149.     int flags;
  150. };
  151.  
  152. /* Cache for the last-used routing entry, speeds up the common case where
  153.  * we handle a burst of packets to the same destination
  154.  */
  155. struct rt_cache {
  156.     int32 target;
  157.     struct route *route;
  158. };
  159. extern struct rt_cache Rt_cache;
  160.  
  161. /* Reassembly descriptor */
  162. struct reasm {
  163.     struct reasm *next;    /* Linked list pointer */
  164.     struct timer timer;    /* Reassembly timeout timer */
  165.     struct frag *fraglist;    /* Head of data fragment chain */
  166.     int16 length;        /* Entire datagram length, if known */
  167.     int32 source;        /* src/dest/id/protocol uniquely describe a datagram */
  168.     int32 dest;
  169.     int16 id;
  170.     char protocol;
  171. };
  172. #define    NULLREASM    (struct reasm *)0
  173.  
  174. /* Fragment descriptor in a reassembly list */
  175. struct frag {
  176.     struct frag *prev;    /* Previous fragment on list */
  177.     struct frag *next;    /* Next fragment */
  178.     struct mbuf *buf;    /* Actual fragment data */
  179.     int16 offset;        /* Starting offset of fragment */
  180.     int16 last;        /* Ending offset of fragment */
  181. };
  182. #define    NULLFRAG    (struct frag *)0
  183.  
  184. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  185.  
  186. /* Structure for handling raw IP user sockets */
  187. struct raw_ip {
  188.     struct raw_ip *next;    /* Linked list pointer */
  189.  
  190.     struct mbuf *rcvq;    /* receive queue */
  191.     void (*r_upcall) __ARGS((struct raw_ip *));
  192.     int protocol;        /* Protocol */
  193.     int user;        /* User linkage */
  194. };
  195. #define    NULLRIP    ((struct raw_ip *)0)
  196. extern struct raw_ip *Raw_ip;
  197.  
  198. /* Transport protocol link table */
  199. struct iplink {
  200.     char proto;
  201.     void (*funct) __ARGS((struct iface *,struct ip *,struct mbuf *,int));
  202. };
  203. extern struct iplink Iplink[];
  204.  
  205. /* In ip.c: */
  206. void ip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  207.     int rxbroadcast));
  208. void ipip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  209.     int rxbroadcast));
  210. int ip_send __ARGS((int32 source,int32 dest,char protocol,char tos,char ttl,
  211.     struct mbuf *bp,int16 length,int16 id,char df));
  212. struct raw_ip *raw_ip __ARGS((int protocol,void (*r_upcall) __ARGS((struct raw_ip *)) ));
  213. void del_ip __ARGS((struct raw_ip *rrp));
  214.  
  215. /* In iproute.c: */
  216. void ipinit __ARGS((void));
  217. int16 ip_mtu __ARGS((int32 addr));
  218. int ip_encap __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,
  219.     int prec,int del,int tput,int rel));
  220. int ip_route __ARGS((struct iface *i_iface,struct iface *r_iface,
  221.     struct mbuf *bp,int rxbroadcast));
  222. int32 locaddr __ARGS((int32 addr));
  223. void rt_merge __ARGS((int trace));
  224. struct route *rt_add __ARGS((int32 target,unsigned int bits,int32 gateway,
  225.     struct iface *iface,int32 metric,int32 ttl,char private));
  226. int rt_drop __ARGS((int32 target,unsigned int bits));
  227. struct route *rt_lookup __ARGS((int32 target));
  228. struct route *rt_blookup __ARGS((int32 target,unsigned int bits));
  229.  
  230. /* In iphdr.c: */
  231. int16 cksum __ARGS((struct pseudo_header *ph,struct mbuf *m,int16 len));
  232. int16 eac __ARGS((int32 sum));
  233. struct mbuf *htonip __ARGS((struct ip *ip,struct mbuf *data,int cflag));
  234. int ntohip __ARGS((struct ip *ip,struct mbuf **bpp));
  235.  
  236. /* In either lcsum.c or pcgen.asm: */
  237. int16 lcsum __ARGS((int16 *wp,int16 len));
  238.  
  239. #endif /* _IP_H */
  240.